using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter07
{
	/// <summary>
	/// Example11: A Block-Spring System
	/// A block of mass 1.6 kg is attached to a horizontal that 
	/// has a force constant of 1.0 \times 10^3 N/m, as shown Figure 7.10.
	/// The spring is compressed 2.0 cm and is then released from rest.
	/// (A) Calculate the speed of the block as it passes through
	/// the equilibrium position x=0 if the surface is frictionless.
	/// v_f = 0.5 m/s
	/// (B) Calculate the speed of the block as if passes through 
	/// the equilibrium position if a constant friction force of
	/// 4.0 N retards it motion from the moment it is released.
	/// v_f = 0.39 m/s
	/// </summary>
	public class Example11
	{
		public Example11()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			double k = 1.0*1000.0; // spring constant
			L.Mass m = new L.Mass();
			m.kg = 1.6;
			L.Displacement d = new L.Displacement();
			d.X = 0.02;
			//(A)
			L.Work W = new L.Work();
			W.J = 0.5*k*d.m*d.m;
			L.KineticEnergy ki = new L.KineticEnergy();
			ki.J = 0.0;
			L.KineticEnergy kf = new L.KineticEnergy();
			kf.VariableQ = true;
			L.FundamentalLaw.WorkEnergyTheorem(ki,W,kf);
			L.Velocity vf = new L.Velocity(m,kf);
			result += Convert.ToString(vf.Norm)+"\r\n";
			//(B)
			L.Work WB = new L.Work();
			WB.J = -4.0*d.X;
			L.Work[] Wp = new L.Work[2];
			Wp[0] = W;
			Wp[1] = WB;		
			L.KineticEnergy kfB = new L.KineticEnergy();
			kfB.VariableQ = true;
			L.FundamentalLaw.WorkEnergyTheorem(ki,Wp,kfB);
			L.Velocity vfB = new L.Velocity(m,kfB);
			result += Convert.ToString(vfB.Norm)+"\r\n";
		}
	}
}
